//
//  LXDSongCollectionViewCell.m
//  BLDMusics
//
//  Created by lxd on 16/3/18.
//  Copyright © 2016年 李晓丹. All rights reserved.
//

#import "LXDSongCollectionViewCell.h"

@implementation LXDSongCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self createControl];
    }
    return self;
    
}

// 创建控件
- (void)createControl {
    self.songImage = [[UIImageView alloc] init];
    [self.contentView addSubview:_songImage];
    
    self.grayView = [[UIView alloc] init];
    [self.songImage addSubview:_grayView];
    
    self.authorLabel = [[UILabel alloc] init];
    [self.songImage addSubview:_authorLabel];
    
    self.lisitenLabel = [[UILabel alloc] init];
    [self.songImage addSubview:_lisitenLabel];
    
    self.titleLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_titleLabel];
    
}

// 控件布局
- (void)layoutSubviews {
    [super layoutSubviews];
    
    _songImage.frame = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.width);
    
    _grayView.frame = _songImage.frame;
    _grayView.backgroundColor = [UIColor blackColor];
    _grayView.alpha = 0.09;
    
    _authorLabel.frame = CGRectMake(10, self.bounds.size.width - 30, self.bounds.size.width, 20);
    _authorLabel.textColor = [UIColor whiteColor];
    _authorLabel.font = [UIFont boldSystemFontOfSize:15];
    
    _lisitenLabel.frame = CGRectMake(self.bounds.size.width - 100, 5, 90, 15);
    _lisitenLabel.textColor = [UIColor whiteColor];
    _lisitenLabel.font = [UIFont boldSystemFontOfSize:14];
    _lisitenLabel.textAlignment = NSTextAlignmentRight;
    
    _titleLabel.frame = CGRectMake(0, self.bounds.size.width + 5, self.bounds.size.width, 15);
    _titleLabel.font = [UIFont systemFontOfSize:16];
}

// model传值
- (void)setModel:(LXDSongModel *)model {
    _model = model;
    [self assignControl];
}

// 控件赋值
- (void)assignControl {
    [_songImage sd_setImageWithURL:[NSURL URLWithString:self.model.pic_url] placeholderImage:[UIImage imageNamed:@"lxd1.png"]];
    _authorLabel.text = self.model.author;
    _lisitenLabel.text = self.model.listen_count;
    _titleLabel.text = self.model.title;
}

@end
